package com.zyd.blog.personal.controller;

import com.zyd.blog.business.annotation.BussinessLog;
import com.zyd.blog.business.enums.ResponseStatus;
import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.personal.service.DesignerService;
import com.zyd.blog.personal.vo.DesignerConditionVo;
import com.zyd.blog.util.ResultUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 审核后的设计师列表
 * @author mfy
 */
@Controller
@RequestMapping("/designer")
public class DesignerController {

    @Resource
    private DesignerService designerService;

    /**
     * 进入设计师用户界面
     * 访问路径 http://localhost:8085/designer/page
     * @return
     */
    @BussinessLog("进入设计师用户界面")
    @GetMapping("/page")
    public ModelAndView front() {
        return ResultUtil.view("personal/list");
    }

    /**
     * 得到设计师列表
     * 访问路径 http://localhost:8085/designer/list
     * @param designerConditionVo   条件
     * @return  结果
     */
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(DesignerConditionVo designerConditionVo) {
        List<Map<String,Object>> designers = designerService.designerList(designerConditionVo);
        return ResultUtil.tablePage((long) designers.size(),designers);
    }


    /**
     * 修改用户状态
     * 访问路径 http://localhost:8085/designer/change
     * @param status    状态
     * @param userId    用户id
     * @return  操作结果
     */
    @RequestMapping("/change")
    @BussinessLog("编辑用户")
    @ResponseBody
    public ResponseVO change(Integer status, Long userId) {
        System.out.println(status);
        System.out.println(userId);
        try {
            designerService.changeStatus(userId,status);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("状态修改失败！");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }

    /**
     * 删除设计师信息
     * 访问路径 http://localhost:8085/designer/delete?userId=
     * @param userId    用户id
     * @return  页面
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseVO delete(Long userId){
        try {
            designerService.deleteDesigner(userId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("删除失败！");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }


    /**
     * 获得设计师详细信息
     * 访问路径 http://localhost:8085/designer/designerDetailPage
     * @return  页面
     */
    @RequestMapping("/designerDetailPage/{id}")
    @ResponseBody
    public ResponseVO designerDetailPage(@PathVariable("id") Long userId) {
        return ResultUtil.success(null, designerService.designerDetailPage(userId));
    }

    /**
     * 查看结束
     * 访问路径 http://localhost:8085/designer/ok
     * @return  查看结束
     */
    @PostMapping("/ok")
    @BussinessLog("查看结束")
    @ResponseBody
    public ResponseVO ok() {
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }

}
